/**
 * 套餐管理初始化
 */
var VpnExclusiveLine = {
    id: "VpnExclusiveLineTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
VpnExclusiveLine.initColumn = function () {
    return [[
            {title: '服务器', field: 'serverIP', align: 'center'},
            {title: '启用时间', field: 'serverCreateTime', align: 'center'},
            // {title: '停用时间', field: 'duration', align: 'center'},
            {title: '已分配用户', field: 'userName', align: 'center'},
            {title: '用户生效时间', field: 'packageStartTime', align: 'center'},
            {title: '用户失效时间', field: 'packageEndTime', align: 'center'},
            {title: '操作', field: 'serverIP',
                align: 'center', templet:function (res) {
                    return "<a onclick=\"VpnExclusiveLine.openExclusivePackageInfoDetail("+res.serverId+")\">修改</a>";
                }}
    ]];
};

/**
 * 点击添加套餐管理
 */
VpnExclusiveLine.openAddVpnExclusiveLine = function () {
    var index = layer.open({
        type: 2,
        title: '新增用户',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/vpnExclusive/vpnExclusiveLine_add'
    });
    this.layerIndex = index;
};

VpnExclusiveLine.openExclusivePackageInfoDetail = function (serverId) {
    var index = layer.open({
        type: 2,
        title: '修改专属线路信息',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/vpnExclusive/vpnExclusiveLine_update/' + serverId
    });
    this.layerIndex = index;
};

/**
 * 删除套餐管理
 */
function deleteExclusiveLinePackage (serverId,userId) {
    layer.confirm("确定删除用户？",{icon:3,title:'提示'},
        function (index) {
            var ajax = new $ax(Feng.ctxPath + "/vpnExclusive/delete", function (data) {
                Feng.success("删除成功!");
                VpnExclusiveLine.refresh();
            }, function (data) {
                Feng.error(data.responseJSON.message);
            });
            ajax.set("serverId",serverId);
            ajax.set("userId",userId);
            ajax.start();
            layer.close(index)
        },function (index) {
            layer.close(index)
        })
};


/**
 * 刷新列表
 */
VpnExclusiveLine.refresh = function(){
    VpnExclusiveLine.table.reload("tableReload",{
        page: {
            curr: 1 //重新从第1页开始
        }
    });
}


VpnExclusiveLine.tableList = function(queryData){
    layui.use("table",function () {
        var table = layui.table;

        VpnExclusiveLine.table = table;

        table.render({
            elem: "#table",
            url: Feng.ctxPath +"/vpnExclusive/list",
            cellMinWidth: 120,
            where: queryData,
            page: true,
            limit: 20,
            cols: VpnExclusiveLine.initColumn(),
            parseData: function(res){
                return{
                    "code":0,
                    "msg":"获取成功",
                    "count":res.total,
                    "data": res.items
                }
            },
            text: {
                none: '暂无相关数据'
            },
            id: "tableReload"
        });
    });
};

$(function () {
    VpnExclusiveLine.tableList();
});
